package ${package}.controller;
import ${package}.entity.${table.className}Entity;
import ${package}.service.${table.className}Service;
import ${package}.dto.${table.className}DTO;
import ${package}.dto.${table.className}QueryCriteria;
import ${package}.dto.converter.${table.className}Converter;
import com.bolt.admin.logging.annotation.LogAnnotation;
import com.bolt.convention.data.PageInfo;
import com.bolt.convention.data.ResultMessage;
import com.bolt.convention.data.Results;
import com.bolt.support.spring.jpa.specification.QueryHelp;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;

/**
* Auto Generate Javadoc
* @author
* 日期:${.now?string("yyyy-MM-dd HH:mm:ss")}
* ${table.remarks?default("")}
**/
@RestController
@RequestMapping("api/${mappingUrl?default("/请修改URL")}")
@RequiredArgsConstructor
@Api(tags ="${table.remarks?default("")}")
public class ${table.className}Controller  {

private final ${table.className}Service ${table.className?uncap_first}Service;

    /**
    * ${table.remarks}列表分页
    * @return
    */
    @PostMapping(value = "/page")
    @ApiOperation(notes = "${table.remarks}列表分页${table.remarks}列表分页", httpMethod = "GET", value = "${table.remarks}列表分页")
    public ResultMessage list(Pageable pageable,${table.className}QueryCriteria queryCriteria) {
        PageInfo <${table.className}Entity> pageInfo =  ${table.className?uncap_first}Service.findPage(pageable,(root, criteriaQuery, criteriaBuilder)
            -> QueryHelp.getPredicate(root, queryCriteria, criteriaBuilder));
            return Results.success(pageInfo.map(K -> ${table.className}Converter.toDTO(K)));
    }

    /**
    * 根据ID${table.remarks?default("")}操作
    */
    @GetMapping("/get/{id}")
    @ApiOperation(notes = "根据ID查询${table.remarks?default("")}", httpMethod = "GET", value = "根据ID查询${table.remarks?default("")}")
    public ResultMessage <${table.className}DTO> get(@PathVariable ${table.pkColumn.javaType} id) {
        ${table.className}Entity ${table.className?uncap_first}Entity = ${table.className?uncap_first}Service.findOne(id).get();
        return Results.success(  ${table.className}Converter.toDTO(${table.className?uncap_first}Entity));
    }

    /**
    * ${table.remarks?default("")}新增操作
    * @param dao 表单数据
    * @return
    */
    @PostMapping
    @ApiOperation(notes = "${table.remarks?default("")}新增", httpMethod = "POST", value = "${table.remarks?default("")}新增")
    @LogAnnotation(module = "${table.remarks?default("")}", description = "${table.remarks?default("")}新增")
    public ResultMessage<Void> create(@Validated @RequestBody ${table.className}DTO dao) {
      ${table.className?uncap_first}Service.saveOrUpdate(dao);
        return Results.success();
    }

    /**
    * ${table.remarks?default("")}编辑操作
    * @param dao 表单数据
    * @return
    */
    @PutMapping
    @ApiOperation(notes = "${table.remarks?default("")}编辑", httpMethod = "PUT", value = "${table.remarks?default("")}编辑")
    @LogAnnotation(module = "${table.remarks?default("")}", description = "${table.remarks?default("")}编辑")
    public ResultMessage<Void> update(@Validated(${table.className}DTO.Update.class) @RequestBody ${table.className}DTO dao) {
        ${table.className?uncap_first}Service.saveOrUpdate(dao);
        return Results.success();
    }

    /**
    * ${table.remarks?default("")}删除操作
    */
     @DeleteMapping
     @ApiOperation(notes = "根据ID删除${table.remarks?default("")}", httpMethod = "DELETE", value = "根据ID删除${table.remarks?default("")}")
     @LogAnnotation(module = "${table.remarks?default("")}", description = "${table.remarks?default("")}删除操作")
     public ResultMessage<Void> doDelete(@RequestBody  Set<${table.pkColumn.javaType}> ids) {
         for (${table.pkColumn.javaType} id : ids) {
           ${table.className?uncap_first}Service.deleteById(id);
         }
         return Results.success();
    }
 }